import vue from "@vitejs/plugin-vue";
import { chunkSplitPlugin } from "vite-plugin-chunk-split";
import vueJSX from "@vitejs/plugin-vue-jsx";
import { defineConfig } from "vite";

const { resolve } = require("path");

// https://vitejs.dev/config/
export default ({ mode }) => {
  return defineConfig({
    plugins: [
      vue(),
      chunkSplitPlugin({
        strategy: "default",
      }),
      vueJSX(),
    ],
    base: "./",
    resolve: {
      alias: {
        "@": resolve(__dirname, "src"), // 设置 `@` 指向 `src` 目录
      },
    },
    server: {
      host: "0.0.0.0",
      port: 8080, // 设置服务启动端口号
      open: true, // 设置服务启动时是否自动打开浏览器
      // 代理
      proxy: {},
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@use "./src/styles/variables.scss" as *;',
        },
      },
    },
    build: {
      outDir: `dist_${mode}`,
      minify: "terser", // boolean | 'terser' | 'esbuild'
      // 生产环境移除 console
      terserOptions: {
        compress: {
          drop_console: true,
          drop_debugger: true,
        },
      },
      chunkSizeWarningLimit: 500,
      rollupOptions: {
        // 打包文件拆分
        output: {
          chunkFileNames: "static/js/[name]-[hash].js",
          entryFileNames: "static/js/[name]-[hash].js",
          assetFileNames: "static/[ext]/[name]-[hash].[ext]",
        },
      },
    },
  });
};

